﻿<!DOCTYPE html>

<html>

<head>
    <meta name="viewport" content="width=device-width" />
    <link href="/SiteUI/Base.css" rel="stylesheet" />
    <link href="/SiteUI/SoBiz/LoginForm.css" rel="stylesheet" />
</head>

<body>
    <div class="view">
        <div class="row" id="loginPanel">
            <div class="col-lg-6" id="standForm">
                <h3>帐号登录</h3>
                <span id="tipForKey"></span>
                <input id="txbKey" placeholder="帐号/手机/邮箱" />
                <span id="tipForPass"></span>
                <input id="txbPass" type="password" placeholder="密码" />
                <span id="tipLogin"></span>
                <div class="button btn-big btn-focus" id="btnLogin">登 录</div>
                <a class="LinkTo" id="lnkRegister" href="/Register.html">注册账号</a>
                <a class="LinkTo" id="lnkFindPass" href="/ForgetPwd.html">忘记密码？</a>
            </div>
            <div class="col-lg-6" id="wxLoginForm">
                <h3>打开微信，扫一扫</h3>
                <span>&nbsp;</span>
                <br />
                <img id="imgWxTmpQr" src="" />
            </div>
        </div>
    </div>
    <script src="/LiberUI/Scripts/jquery.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Base.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Action.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.js"></script>
    <script src="/SiteUI/res_sobiz.js"></script>
    <script>
        var LoginForm = {

        };
        function onLogin(ev) {
            LoginForm.chkAcnt.check();
            LoginForm.frmLogin.disable();
            $("#tipLogin").vl("");
            $("#btnLogin").vl("正在登录...").addClass("disabled");
            $.post("/SoBiz/Login", { key: $("#txbKey").vl(), pass: $("#txbPass").vl() }, onLoginEnd);
        };
        function onLoginEnd(rtn) {
            if (rtn.IsPositive) {
                window.top.location = "/SoBiz/LoginEnd";
            }
            else {
                var msg = ErrFormate(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error)
                $("#tipLogin").vl(msg);
                $("#btnLogin").vl("登录").removeClass("disabled");
                LoginForm.frmLogin.enable();
            }
        };
        function onLoginByWxEnd(rtn) {
            if (rtn.IsPositive) {
                LoginForm.frmLogin.disable();
                $("#tipLogin").vl("");
                $("#btnLogin").vl("登录成功..").addClass("disabled");
                $.post("/SoBiz/Login", { 'opensrc': 'wechat' }, function (rtn) {
                    if (rtn.IsPositive) {
                        window.location = "/SoBiz/LoginEnd";
                    }
                    else {
                        window.location = "/Register.html?from=wechat";
                    }
                })
            }
            else {
                setTimeout(onLoginByWx, 500);
            }
        };
        function onLoginByWx() {
            $.getJSON("/TLB2B/IfWxTmpQRScaned?tm=" + new Date().getTime(), null, onLoginByWxEnd);
        };
        function onGetTicketEnd(rtn) {
            //TODO:获得微信临时二维码Ticket,直接从微信服务器获取二维码地址
            rtn = JSON.parse(rtn);
            if (rtn.ticket) {
                setTimeout(function () {
                    $("#wxLoginForm").fadeIn();
                    $("#imgWxTmpQr").attr("src", "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + encodeURI(rtn.ticket));
                }, 1000);

                //开始检查用户扫码
                setTimeout(onLoginByWx, 200);
            }
        };

        $(function () {
            $.ajax({
                cache: false,
                async: true,
                timeout: 10000,
                error: function (rtn, ev) {
                    if (rtn.status == '401') {
                        window.location = "/Index.html";
                    }
                }
            });
            $("#standForm").fadeIn();
            LoginForm.frmLogin = new LiberUI.Form("#standForm")
                                       .on("submiting", onLogin)
                                       .focus();
            $("#btnLogin").on("click", function () { LoginForm.frmLogin.Submit(); });

            LoginForm.chkAcnt = new Validater().noEmpty($("#txbKey"), $("#tipForKey"), "账号不能为空", "", true);

            //获取微信临时二维码
            $.getJSON("/TLB2B/GetWxTmpQRTicket", {}, onGetTicketEnd);
            //检查上次登录账号（在服务端设置的）
            var la = $.Cookie("LastAccount");
            if (la != null) {
                $("#txbKey").vl(la);
                $("#txbPass").focus();
            };
            
        });
    </script>
</body>
</html>
